#include "Candeeiro.h"

Candeeiro::Candeeiro() { }

void Candeeiro::drawface1()
{
	GLfloat ctrlpoints[4][3] = { {-1.0,0.0,-1.0},{1.0,0.0,-1.0},
								 {-3.0,2.0,-3.0},{3.0,2.0,-3.0}};
	GLfloat textpoints[4][2] = {	{ 0.0, 0.0},
								{ 0.0, 1.0}, 
								{ 1.0, 0.0},
								{ 1.0, 1.0} };
	glMap2f(GL_MAP2_VERTEX_3, 0.0, 1.0, 3, 2,  0.0, 1.0, 6, 2,  &ctrlpoints[0][0]);
	glMap2f(GL_MAP2_TEXTURE_COORD_2,  0.0, 1.0, 2, 2,  0.0, 1.0, 4, 2,  &textpoints[0][0]);
	glEnable(GL_MAP2_VERTEX_3);
	//glEnable(GL_MAP2_TEXTURE_COORD_2);
	glShadeModel(GL_SMOOTH);					
	//glEnable(GL_TEXTURE_2D);
	glMapGrid2f(10, 0,1, 10, 0.0,1); 
	glEvalMesh2(GL_FILL, 0,10, 0,10);
}

void Candeeiro::drawface2()
{
	GLfloat nrmlcompon[4][3] = {	{  0.0, 1.0, 0.0},
									{  0.0, 1.0, 0.0}, 
									{  0.0, 1.0, 0.0},
									{  0.0, 1.0, 0.0} };
	GLfloat ctrlpoints[4][3] = { {-3.0,2.0,3.0},{3.0,2.0,3.0},
								{-1.0,0.0,1.0},{1.0,0.0,1.0}};
	GLfloat textpoints[4][2] = {	{ 0.0, 0.0},
								{ 0.0, 1.0}, 
								{ 1.0, 0.0},
								{ 1.0, 1.0} };
	glMap2f(GL_MAP2_VERTEX_3, 0.0, 1.0, 3, 2,  0.0, 1.0, 6, 2,  &ctrlpoints[0][0]);
	glMap2f(GL_MAP2_TEXTURE_COORD_2,  0.0, 1.0, 2, 2,  0.0, 1.0, 4, 2,  &textpoints[0][0]);
	glEnable(GL_MAP2_VERTEX_3);
	//glEnable(GL_MAP2_TEXTURE_COORD_2);
	glShadeModel(GL_SMOOTH);					
	//glEnable(GL_TEXTURE_2D);
	glMapGrid2f(10, 0,1, 10, 0.0,1); 
	glEvalMesh2(GL_FILL, 0,10, 0,10);
}

void Candeeiro::drawface3()
{
	GLfloat nrmlcompon[4][3] = {	{  0.0, 1.0, 0.0},
									{  0.0, 1.0, 0.0}, 
									{  0.0, 1.0, 0.0},
									{  0.0, 1.0, 0.0} };
	GLfloat ctrlpoints[4][3] = { {-1.0,0.0,1.0},{1.0,0.0,1.0},
								{-1.0,0.0,-1.0},{1.0,0.0,-1.0}};
	GLfloat textpoints[4][2] = {	{ 0.0, 0.0},
								{ 0.0, 1.0}, 
								{ 1.0, 0.0},
								{ 1.0, 1.0} };
	glMap2f(GL_MAP2_VERTEX_3, 0.0, 1.0, 3, 2,  0.0, 1.0, 6, 2,  &ctrlpoints[0][0]);
	glMap2f(GL_MAP2_TEXTURE_COORD_2,  0.0, 1.0, 2, 2,  0.0, 1.0, 4, 2,  &textpoints[0][0]);
	glEnable(GL_MAP2_VERTEX_3);
	//glEnable(GL_MAP2_TEXTURE_COORD_2);
	glShadeModel(GL_SMOOTH);					
	//glEnable(GL_TEXTURE_2D);
	glMapGrid2f(10, 0,1, 10, 0.0,1); 
	glEvalMesh2(GL_FILL, 0,10, 0,10);

}

void Candeeiro::draw()
{
	glCullFace(GL_FRONT);
	glEnable(GL_AUTO_NORMAL);
	glPushMatrix();
	glRotated(180,1,0,0);
	drawface1();
	drawface2();
	glPushMatrix();
		glRotated(90,0,1,0);
		drawface1();
		drawface2();
	glPopMatrix();
	drawface3();
	glPopMatrix();

	glPushMatrix();
	glEnable(GL_CCW);
	glRotated(180,1,0,0);
	drawface1();
	drawface2();
	glPushMatrix();
		glRotated(90,0,1,0);
		drawface1();
		drawface2();
	glPopMatrix();
	drawface3();
	glPopMatrix();
	glDisable(GL_AUTO_NORMAL);
	glCullFace(GL_BACK);
}